<!--
描述：系统应用-菜单管理-菜单添加、编辑
开发人：hqj
开发日期：2018年05月25日
-->
<template lang="pug">
    kalix-dialog.user-add(bizKey="enrolmentPaper" ref="kalixBizDialog" v-bind:formModel.sync="formModel" v-bind:targetURL="targetURL" v-bind:editCustom="formModel.cfgKey")
        div.el-form.kalix-form-table(slot="dialogFormSlot")
            div.s-flex
                el-form-item.s-flex_item.kalix-form-table-td(label="年份" prop="year" v-bind:rules="rules.year" v-bind:label-width="labelWidth")
                    kalix-date-picker(v-model="formModel.year" type="year")
                el-form-item.s-flex_item.kalix-form-table-td(label="学期" prop="term" v-bind:rules="rules.term" v-bind:label-width="labelWidth")
                    kalix-dict-select(v-model="formModel.term" appName="enrolment" dictType="学期")
            div.s-flex
                el-form-item.s-flex_item.kalix-form-table-td(label="试卷名称" prop="title" v-bind:rules="rules.title" v-bind:label-width="labelWidth")
                    el-input(v-model="formModel.title" )
            div.s-flex
                el-form-item.s-flex_item.kalix-form-table-td(label="模板名称" prop="tempName" v-bind:rules="rules.tempName" v-bind:label-width="labelWidth")
                    kalix-dict-select(v-model="formModel.tempName" appName="enrolment" dictType="模板名称")
            template(v-if="formModel.tempName === '1' ")
                el-form-item.s-flex_item.kalix-form-table-td(label="考试科目" prop="kskm" v-bind:rules="rules.kskm" v-bind:label-width="labelWidth")
                    kalix-dict-select(v-model="formModel.kskm" appName="enrolment" dictType="考试科目")
            template(v-if="formModel.tempName === '2' ")
                el-form-item.s-flex_item.kalix-form-table-td(label="主观题类型" prop="kskm" v-bind:rules="rules.kskm" v-bind:label-width="labelWidth")
                    kalix-dict-select(v-model="formModel.kskm" appName="enrolment" dictType="主观题类型")
            template(v-if="formModel.tempName === '3' ")
                el-form-item.s-flex_item.kalix-form-table-td(label="面试题类型" prop="kskm" v-bind:rules="rules.kskm" v-bind:label-width="labelWidth")
                    kalix-dict-select(v-model="formModel.kskm" appName="enrolment" dictType="面试题类型")
                el-form-item.s-flex_item.kalix-form-table-td(label="题型范围" prop="quesRange" v-bind:rules="rules.quesRange" v-bind:label-width="labelWidth" )
                    el-select(v-model='formModel.currentYears' v-on:change="selectChange" placeholder='请选择年份' multiple  style="width:100%;")
                        el-option(v-for="item in items" v-bind:key="item.value" v-bind:label="item.label" v-bind:value="item.value")
            div.s-flex
                el-form-item.s-flex_item.kalix-form-table-td(label="自动成卷份数" prop="copies" v-bind:rules="rules.totalMark" v-bind:label-width="labelWidth")
                    el-input(v-model="formModel.copies" )
            template(v-if="formModel.tempName != '3' ")
                el-form-item.s-flex_item.kalix-form-table-td(label="总分" prop="totalMark" v-bind:rules="rules.totalMark" v-bind:label-width="labelWidth")
                    el-input(v-model="formModel.totalMark" )
            input(type="hidden" v-model="hidenText")
</template>

<script type="text/ecmascript-6">
    import FormModel from './paperModel'
    import {AutoPaperURL} from '../config.toml'
    import {getServerCurrentDateYear} from '../common.js'
    export default {
        name: 'PaperModuleAdd',
        data() {
            return {
                formModel: Object.assign({}, FormModel),
                rules: {
                    year: [{required: true, message: '试卷年份不能为空', trigger: 'blur'}],
                    title: [{required: true, message: '试卷名称不能为空', trigger: 'blur'}],
                    kskm: [{required: true, message: '考试科目不能为空', trigger: 'blur'}],
                    term: [{required: true, message: '学期不能为空', trigger: 'blur'}],
                    tempName: [{required: true, message: '模板名称不能为空', trigger: 'blur'}],
                    totalMark: [{required: true, message: '试卷总分不能为空', trigger: 'blur'}],
                    quesRange: [{required: true, message: '试题范围不能为空', trigger: 'blur'}]
                },
                targetURL: AutoPaperURL,
                labelWidth: '110px',
                items: [],
                hidenText:'',
                currentDateYear: (new Date()).getFullYear()
            }
        },
        components: {},
        watch: {
          formModel: {
            handler: 'watchFormModel',
            deep: true
          }
        },
        created() {
            getServerCurrentDateYear(this.axios, this.$KalixMessage, flag => {
                this.currentDateYear = flag
                for (let i = 6; i > -2; i--) {
                    this.items.push({
                        value: this.currentDateYear * 1 - i,
                        label: this.currentDateYear * 1 - i
                    })
                }
                this.initCurrentValue()
            })
        },
        methods: {
          watchFormModel(newValue) {
              if (newValue.targetURL) {
                  this.targetURL = newValue.targetURL
              }
              this.initCurrentValue()
          },
            selectChange() {
                this.hidenText = (new Date()).getTime()
                this.initCurrentValue()
            },
            initCurrentValue() {
                if (this.formModel.currentYears && this.formModel.currentYears.length) {
                    this.formModel.quesRange = this.formModel.currentYears.join(',')
                } else {
                    this.formModel.quesRange = null
                }
            }
        }
    }
</script>

<style scoped>
</style>
